<template>
  <div style="height: 100%;background-color: white">
    <div class="custBox">
      <div class="operation">
        <div class="operation_left">
          <span v-show="select_num == 0">共{{total}}个客户</span>
          <span v-show="select_num > 0">已选中{{select_num}}个</span>

          <el-button size="mini" style="margin: 0 5px" @click="senMail" :disabled="select_num == 0">发送邮件</el-button>
          <el-button size="mini" style="margin: 0 5px" @click="dealingsMail" :disabled="edit_boolean">来往邮件</el-button>

          <el-button size="mini" style="margin: 0 5px" @click="cancelCustShare" :disabled="select_num == 0">取消共享</el-button>


        </div>
        <div class="operation_right search">
          <el-autocomplete
            size="mini"
            class="inline-input"
            style="width:220px;margin: 0 10px"
            v-model="input"
            @keyup.enter.native="search"
            @change="replace"
            :fetch-suggestions="querySearch"
            :trigger-on-focus="false"
            placeholder="请输入客户名称/联系人/邮箱查询">
            <el-button slot="append" style="cursor: pointer;" @click="search">
              <i class="el-icon-search"></i>
            </el-button>
          </el-autocomplete>
        </div>
      </div>
      <!--                     -->
      <el-dialog
        :close-on-click-modal="false" :close-on-press-escape	='false'
        :visible.sync="centerDialogVisible"
        width="300px"
        append-to-body
        :show-close="true"
        @close="closeCustShow"
        center>
          <span slot="title" class="dialog-title">
            客户列表显示字段设置
          </span>
        <div style="height: 300px">
          <el-checkbox-group v-model="copyCheckList" :min="1" @change="changeCheck">
            <div v-for="(value,index3) in showlist" :key="index3" style="padding-left: 85px;margin: 5px 0">
              <el-checkbox :label="value.name" :disabled="value.name =='客户名称' "></el-checkbox>
            </div>
          </el-checkbox-group>
        </div>
        <span slot="footer" class="dialog-footer">
            <el-button @click="closeCustShow" size="small" type="primary" plain>取 消</el-button>
            <el-button type="primary" @click="custShow" :loading="loading" size="small">保存</el-button>
          </span>
      </el-dialog>
      <div class="table_box">
        <div class="icon icon_left">
          <span class="icon-shaixuan" @click="centerDialogVisible = true"></span>
        </div>
        <!-- :max-height="tableHeight" -->

        <el-table
          v-if="load"
          :header-row-style="{background:'#EAF0F6'}"
          ref="multipleTable"
          :data="tableData"
          @selection-change='selectList'
          :row-style="rowClass"
          tooltip-effect="dark"
          style="width: 100%"
          :height="tableHeight"
          class="table"
          @sort-change="sortChange"
          @row-click="preview">
          <el-table-column
            type="selection"
            :fixed="true"
            width="55">
          </el-table-column>

          <template v-for="(col, index) in headerList">
            <el-table-column
              :width="col.field == 'light' ? 80 : 200"
              :label="col.name"
            >
              <template slot-scope="scope">
                <tableTemplate :col="scope.row" :label="col.field" :jurisdiction="jurisdiction" @jump="toDetail" @handleChange="changeRate" @handleCancel="unlabel" @handleSign="star" custType="share"></tableTemplate>
              </template>
            </el-table-column>
          </template>

          <el-table-column
            width="40"
            fixed="right"
            title="列表显示字段">
          </el-table-column>
          <div slot="empty" style="width: 100%;text-align: left;margin-lrft:-250px">
            <div>
              <img :src="empty" alt="" style="width: 250px" />
            </div>
          </div>
        </el-table>

      </div>
      <div class="footer">
        <el-pagination align="right" class="fixed"
                       v-show="total > 0"
                       @size-change="handleSizeChange"
                       @current-change="handleCurrentChange"
                       :current-page.sync="nowPage"
                       :page-sizes="[10, 20, 30, 50]"
                       :page-size="nowSize"
                       layout="total, sizes, prev, pager, next, jumper"
                       :total="total">
        </el-pagination>
      </div>


      <el-dialog :visible.sync="cancel_show"
                 center append-to-body width="500px"
                 :close-on-click-modal="false"
                 :close-on-press-escape	='false'>
        <p slot="title" class="dialog-title">取消跟进客户</p>
        <div style="font-size:13px;text-align: center;line-height: 20px">
          <p style="font-weight: 600">您确定要取消跟进如下{{selectName.length}}个客户吗？</p>
          <p style="margin-top: 5px">
            <span style="font-weight: 600" v-for="(item,index) in selectName" :key="index"> <span v-if="index != 0">,</span>{{item}} </span>
          </p>
        </div>
        <div slot="footer" class="dialog-footer">
          <el-button @click="cancel_show = false" size="small">取　　消</el-button>
          <el-button type="primary" @click="cancelCust" size="small">取消跟进</el-button>
        </div>
      </el-dialog>

      <drawer v-if="drawerShow" :custId ="nowId" :visible="visShow" @callback="closeDrawer" type="4"></drawer>
      <!--选择联系人-->
      <DialogLinker ref="dialogLinker"></DialogLinker>
    </div>
  </div>
</template>
<script>
    import tableTemplate from '@/components/customer/tableTemplate'
    import editCompany from '@/components/customer/company'
    import Mail from '@/views/mail/draft/edit'
    import {queryShareCust,lightCustInfo, queryCustMark, saveCustMark, deleteBatchCust, markCust, moveGroup, queryCust, shareCust, transferCust, getCustField, setCustField, getFlowUp, cancelFlowUp, delMarkCust, fullNameStore,changeRate, findUserByCrop, canCelCust} from '@/api/customer'
    import {getCustomerEmail} from '@/util/util'
    import drawer from './template/drawer'

    import DialogLinker from '@/components/customer/dialogLinker'
    import {mapGetters,mapState} from "vuex"
    export default {
        data() {
            return {
                empty:'./img/empty.png',
                load:false,
                jurisdiction:{}, // 客户权限按钮
                drawerShow: false, // 详情页组件
                visShow: false, // 抽屉显隐
                nowId: '', // 当前客户id
                isActive: true, // 默认隐藏
                showMail:false, // 默认显示发邮件
                purchase: true, // 采购供应切换
                send_mail_show: false, // 发送邮件弹框
                dialogVisible: false, // 右侧详情页
                edit_boolean: true, // 是否可以编辑
                label_show: false, // 新建标签的显示
                cloorPickerShow: '', // 颜色选择
                colorBg: '', // 背景选择颜色
                colorArray:['#000000', '#BE5957', '#DA762F', '#139891', '#4A669F', '#595AC1', '#333333', '#E63C38', '#EC994D', '#5DBD7F', '#5B87ED', '#8D50BF', '#7B8291', '#F07A79', '#E3AE02', '#7EC65E', '#45A7EE', '#ACACAC'],
                centerDialogVisible: false, // 表头显示
                checkList: [], // 显示表头数组
                copyCheckList: [], // 深拷贝复制选择
                edittacts_show: false,
                markList: [], // 标记为
                headerList:[], // 选中表头集合，用来遍历表头
                showlist: [], // 显示表头数组
                dialogFormVisible: false,
                select_num: 0, // 多选的条数
                total: 0, // 总条数
                nowPage: 1, // 当前页
                input: '', // 输入框
                value: '',
                tableData: [],
                activeName: 'second',
                size: 'medium',
                selectData: [], // 多选数组
                selectIds: [], // 多选ids
                selectName: [], // 多选姓名
                selectRow: [],
                transferDialog: false,
                selectTitle: '', // 树形select框title
                shareDialog: false,
                cancel_show: false,
                selectionId: '',
                selectValue: '',
                mergeOptions: [],
                senior: false,
                second_menu1: false,
                second_menu2: false,
                lableList: [],
                groupingList: [],
                group_num: 0,
                lable_num: 0,
                delete_show: false,
                nowData: '', // 当前右键所选中的数据
                nowSize: 10, //当前页显示条数
                markName: '',
                delete_type: '', // 删除状态，控制单删还是多选删除
                markDto: [], // 标记为的数组
                markArr: [], // 标记id组
                editData: '',
                followContent: '', // 跟进内容
                editCon_title: '',
                contactsData: '',
                contactsIndex: '', // 当前编辑联系人的索引
                userOptions: [], // 当前企业下所有用户
                shareValue: [], // 共享数组
                transferValue: [], // 分享数组
                isPublic: '', // 是否是公海客户
                custType: '', // 客户分组类型
                userId: this.$route.params.userId , // 下属客户id
                props: {
                    value: "id",
                    label: "folderName",
                    children: "children"
                },
                isClearable: true, // 可清空（可选）
                isAccordion: true, // 可收起（可选）
                sortField: '', // 排序的id
                sortType: '', // 排序方式 （正序倒序）
                defaultEmail: [],
                typeids: [], // 分组id集合
                lables: [], // 标签id集合
                userTree: [], // 共享，转移数组
                flowUpList: [], // 跟进记录信息
                flowUpTotal:0, // 跟进记录条数
                flowUpContent: '', // 跟进记录搜索
                tiemOptions: [{
                    value: 'ASC',
                    label: '时间正序'
                },
                    {
                        value: 'DESC',
                        label: '时间倒序'
                    },
                ],
                flowUpType: 0, // 默认事类型为全部
                timeSort: 'DESC', // 默认时间顺序为倒序
                custId: '',
                companyShow: false,   // 强制刷新组件的方法
                tips: [],
                manager: '',
                shareArr: [], // 分享的数组
                transferArr: '', // 转移的数组
                screenHeight: document.documentElement.clientHeight,
                tableHeight: document.documentElement.clientHeight - 177,
                loading:false
            }
        },
        computed: {
            ...mapState(['common']),
            ...mapGetters(["permission"]),
        },
        watch: {
            selectData(value) {
                this.selectRow = []
                if (value.length > 0) {
                    value.forEach((item) => {
                        this.selectRow.push(this.tableData.indexOf(item))
                    })
                }
            },
            flowUpType(value) {
                this.nowPage = 1
                getFlowUp(1,10, this.nowData.id, this.flowUpContent, this.timeSort,value).then(res => {
                    if (res.data.success) {
                        this.flowUpList = res.data.data.records
                        this.flowUpTotal = res.data.data.total
                    }
                })
            },
            timeSort(value) {
                this.nowPage = 1
                console.log(this.nowPage)
                getFlowUp(1,10, this.nowData.id, this.flowUpContent, value,this.flowUpType).then(res => {
                    if (res.data.success) {
                        this.flowUpList = res.data.data.records
                        this.flowUpTotal = res.data.data.total
                    }
                })
            },
            '$route': function (to) {
                this.typeId = to.params.typeId
                this.init()
            }
        },
        components: {
            editCompany,
            Mail,
            drawer,
            DialogLinker,
            tableTemplate
        },
        created() {
            this.jurisdiction = this.vaildData(this.permission)
            getCustField().then(res => { // 列表显示字段
                if (res.data.success) {
                    res.data.data.forEach(value =>{
                        value.show = value.isshow == 0 ? false : true
                        if(value.show) {
                            this.checkList.push(value.name)
                            this.headerList.push(value)
                        }
                    })
                    this.showlist = res.data.data
                    this.copyCheckList = this.checkList
                    this.load = true
                }
            })

            findUserByCrop().then(res => { // 公司下所有员工
                if (res.data.success) {
                    this.userTree = res.data.data
                }
            })
            this.init()

            queryCustMark(this.userId).then((res) => { // 请求标记的数组
                this.markList = res.data.data
                this.lableList = JSON.parse(JSON.stringify(res.data.data))
                var obj ={
                    corpid: "000000",
                    custid: "",
                    id: -1,
                    markName: "+新建标签",
                }
                this.lableList.push(obj)
            })

            fullNameStore().then(res => { // 输入建议
                this.tips = res.data.data
            })

        },
        mounted() {
            //新建客户信息
            if(this.$route.query.type){
                this.showlog();
            }
            document.addEventListener('click', ()=> {
                this.cloorPickerShow = false
            })
            window.onresize = () => {
                this.$nextTick(() => {
                    this.screenHeight = document.documentElement.clientHeight
                    this.tableHeight = this.screenHeight - 177
                })
            }

        },
        methods: {
            toDetail(id){
                sessionStorage.setItem("lastpathcus", this.$route.fullPath)
                this.$router.push(`/customer/shareDetail/${id}`);
            },
            senMail() { // 发送邮件
                if (this.common.emailList.length == 0) {
                    this.$confirm(' <div style="margin: 20px 10px;">\n' +
                        '        <p style="line-height: 30px;\n' +
                        '        font-size: 14px;">您需要先绑定自己的常用邮箱到我们的平台，才可以使用邮件模块功能哦！</p>\n' +
                        '        <p style="line-height: 30px;\n' +
                        '        font-size: 14px;">点击下方的按钮即可立即去绑定。</p>\n' +
                        '      </div>', '邮箱绑定提醒', {
                        dangerouslyUseHTMLString: true,
                        confirmButtonText: '去绑定',
                        cancelButtonText: '取 消',
                    }).then(() => {
                        this.$store.commit('SET_CURRENTSETFRAG', 'eight')
                        this.$router.push('/mail/administration');
                    }).catch(() => {
                    })
                    return;
                } else {
                    this.$refs.dialogLinker.init(this.selectData)
                }
            },
            cancelCustShare() { // 取消共享
                this.$confirm('取消共享后，您将看不到选中客户的所有信息，您确定要取消共享吗？', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: "success"
                }).then(() => {
                    canCelCust(this.selectIds.toString()).then(res => {
                        if(res.data.success) {
                            this.$message({
                                type: 'success',
                                message: res.data.msg
                            });
                            this.init()
                            this.bus.$emit('updataCustMenu')
                        }
                    })


                })
            },
            dealingsMail() { // 来往邮件
                this.getCustomerInfo()
            },
            init() { // 初始化，获得新数据
                queryShareCust(this.$route.params.typeId, this.input, this.lables.toString(), this.typeids.toString(), this.nowPage,this.nowSize, this.sortField, this.sortType).then(res => { // 查询客户列表
                    if(res.data.success) {
                        this.tableData = res.data.data.records
                        this.total = res.data.data.total // 总页数
                        this.nowPage = res.data.data.current // 当前页数
                    }
                })
            },

            cancelLabel() { // 标签弹框关闭
                this.label_show = false
                this.markName = ''
                this.colorBg = ''
            },
            querySearch(queryString, cb) {
                var tips = this.tips;
                console.log(tips.filter(this.createFilter(queryString)))
                var results = queryString ? tips.filter(this.createFilter(queryString)) : tips;
                // 调用 callback 返回建议列表的数据
                cb(results);
            },
            changeRate(value, rate) { // 更改评级
                changeRate(value, rate).then(res => {
                    if (res.data.success) {
                        this.$message({
                            message:res.data.msg,
                            type: 'success'
                        })
                        this.init()
                    }
                })
            },
            createFilter(queryString) { // 搜索框过滤
                return (restaurant) => {
                    return (restaurant.value.toLowerCase().indexOf(queryString.toLowerCase()) === 0);
                };
            },
            replace() {
                var str = this.input
                this.input = str.replace(/\<|\>/g, '')
            },
            unlabel(custId,markId) { // 取消标签
                delMarkCust(custId,markId).then((res) => {
                    if(res.data.success) {
                        this.$message({
                            type:'success',
                            message:'删除标签成功'
                        })
                        this.init()
                    }
                })
            },
            custShow() { // 更改客户表头设置
                this.loading = true
                this.showlist.forEach((value) => {
                    if (this.copyCheckList.indexOf(value.name) > -1) {
                        value.isshow = 1 // 更改为true
                    } else {
                        value.isshow = 0 //跟改为false
                    }
                })
                setCustField(this.showlist).then(res => {
                    if (res.data.success) {
                        this.$message({
                            type: 'success',
                            message: res.data.msg
                        })
                        getCustField().then(res => { // 列表显示字段
                            if (res.data.success) {
                                this.checkList = []
                                this.headerList = []
                                res.data.data.forEach(value =>{
                                    value.show = value.isshow == 0 ? false : true
                                    if(value.show) {
                                        this.checkList.push(value.name)
                                        this.headerList.push(value)
                                    }
                                })
                                this.$nextTick(() => {
                                    this.showlist = res.data.data
                                    this.copyCheckList = this.checkList
                                })
                            }
                        })
                        this.loading = false
                        this.centerDialogVisible = false
                    }
                }).catch(()=> {
                    this.loading = false
                })
            },

            closeCustShow() { // 取消客户表头设置
                this.centerDialogVisible = false
                this.copyCheckList = this.checkList
            },

            cancelCust() { // 取消跟进客户
                cancelFlowUp(this.selectIds.toString()).then(res => {
                    if (res.data.success) {
                        this.$message({
                            type:'success',
                            message:res.data.msg
                        })
                        this.cancel_show = false
                        this.bus.$emit('updataCustMenu')
                        this.init()
                    }
                })
            },

            toMail() { // 跳转到往来邮件
                this.$router.push(`/mailCustomer/${this.nowData.id}`)
            },
            sortChange(order) { // sort 排序发生变化
                switch(order.prop) {
                    case 'light':
                        this.sortField = 'Light' // 标记
                        break;
                    case 'city':
                        this.sortField = 'country_icon' // 城市
                        break;
                    case 'talkNum':
                        this.sortField = 'talk_num' // 沟通次数
                        break;
                }

                        if(order.order == 'ascending') {
                    this.sortType = 'ASC'
                } else {
                    this.sortType = 'Desc'
                }
                this.init()
            },
            moveCust(item) { // 移动客户分组
                moveGroup(this.nowData.id, item.id).then(res => {
                    if (res.data.success) {
                        this.$message({
                            message: res.data.msg,
                            type: 'success'
                        })
                    }
                })
                //    刷新左侧菜单
                this.bus.$emit('updataCustMenu')

            },
            sharedCust() { // 共享
                this.shareDialog = false
                let arr = []
                if (this.shareArr) {
                    this.selectData.forEach(value => {
                        arr.push(value.id)
                    })
                    shareCust(arr.toString(),this.shareArr.toString()).then(res => {
                        if(res.data.success) {
                            this.$message({
                                type:'success',
                                message: res.data.msg
                            })
                            this.bus.$emit('updataCustMenu')
                            this.init()
                        }
                    })
                }
            },
            cancelShare() {
                this.shareDialog = false
                this.shareArr = []
            },
            cancelTransfer () { // 取消转移
                this.transferDialog = false
                this.transferArr = ''
            },
            transferCust() { // 转移
                let arr = []
                this.transferDialog = false
                if(this.transferArr) {
                    this.selectData.forEach(value => {
                        arr.push(value.id)
                    })
                    transferCust(arr.toString(), this.transferArr).then(res => {
                        if (res.data.success) {
                            this.$message({
                                type:'success',
                                message: res.data.msg
                            })
                            this.$emit('updataCustMenu')
                            this.init()
                        }
                    })
                }
            },
            addMark() { // 新增标签
                saveCustMark(this.colorBg, this.markName, this.userId).then((res) => {
                    if(res.data.success) {
                        this.markName = ''
                        this.colorBg = ''
                        this.label_show = false

                        queryCustMark(this.userId).then((res) => { // 请求标记的数组
                            this.lableList = res.data.data
                            var nowMarkId =  this.lableList[this.lableList.length -1].id

                            var arr = []
                            this.selectData.forEach(value => {
                                arr.push(value.id)
                            })

                            markCust(arr.toString(),nowMarkId).then(res => {
                                this.markDto = []
                                this.markArr = []
                                this.$message({
                                    type:'success',
                                    message: res.data.msg
                                })
                                // 重新请求数据
                                var obj ={
                                    corpid: "000000",
                                    custid: "",
                                    id: -1,
                                    markName: "+新建标签",
                                }
                                this.lableList.push(obj)


                                this.init()
                            })
                        })
                    }
                })
            },
            checkbox(event,value, arr) { // checktbox 点击
                if (value == 'grouping') {
                    if (this.typeids.length == arr.length) {
                        this.typeids = []
                    } else {
                        this.typeids = []
                        arr.forEach((key) => {
                            this.typeids.push(key.id)
                        })
                    }
                } else {
                    if (this.lables.length == arr.length) {
                        this.lables = []
                    } else {
                        this.lables = []
                        arr.forEach((key) => {
                            this.lables.push(key.id)
                        })
                    }
                }
                this.search() // 点击进行高级搜索
            },
            active(event, value, item) { // button 点击变色
                if (value == 'grouping') {
                    if (this.typeids.indexOf(item) > -1) {
                        this.typeids.forEach((key,index) => {
                            if (key == item) {
                                this.typeids.splice(index,1)
                            }
                        })
                    } else {
                        this.typeids.push(item)
                    }
                } else {
                    if (this.lables.indexOf(item) > -1) {
                        this.lables.forEach((key,index) => {
                            if (key == item) {
                                this.lables.splice(index,1)
                            }
                        })
                    } else {
                        this.lables.push(item)
                    }
                }
                this.search() // 点击进行高级搜索
            },
            star(value, index) { // 点亮改变状态
                let type = ''
                if (value == 0) {
                    type = 1
                } else {
                    type = 0
                }
                lightCustInfo(index, type).then(() => {
                    this.init()
                })
            },
            show_editContacts(item, index) {
                if (item) {
                    this.editCon_title = '编辑联系人'
                    this.contactsIndex = index
                    this.contactsData = item
                } else {
                    this.editCon_title = '新增联系人'
                    this.contactsData = {
                        'firstName': '',
                        'lastName': '',
                        'email': '',
                        'postType': '',
                        'telFax': ''
                    }
                    this.contactsIndex = ''
                }
                this.edittacts_show = true
            },
            search() { // 搜索
                this.nowPage = 1
                this.init()
            },
            deleteCust() { // 删除
                let removeArr = []
                this.selectData.forEach(value => {
                    removeArr.push(value.id)
                })
                deleteBatchCust(removeArr).then((res) => {
                    if(res.data.success) {
                        this.$message({
                            type: 'success',
                            message: res.data.msg
                        })
                        this.delete_show = false
                        this.init()
                        this.bus.$emit('updataCustMenu')
                    }
                })
            },
            selectColor(e) { // 更改颜色
                if (e.target.nodeName === 'LI') {
                    var check = document.getElementsByClassName('el-icon-check')
                    for (var i = 0; i < check.length; i++) {
                        check[i].remove()
                    }
                    var i = document.createElement('i')
                    i.className = 'el-icon-check'
                    e.target.appendChild(i)
                    this.colorBg = e.target.style.background
                }
            },
            cloorPicker(e) { // 显示颜色选择器
                e.preventDefault()
                this.cloorPickerShow = true
            },
            changeCheck(value) { // 设置公司名称为必选
                if(value.indexOf('客户名称') < 0) {
                    this.checkList.push('客户名称')
                }
                // this.checkList.push('公司名称')
            },
            advancedSearch() { // 高级搜索的显示与隐藏
                this.senior = !this.senior
            },
            selectList(selection) { // table的全选
                if (selection.length == 1) {
                    this.edit_boolean = false
                } else {
                    this.edit_boolean = true
                }
                this.select_num = selection.length
                this.selectData = selection
                this.selectIds = []
                this.selectName = []
                this.selectData.forEach((value) => {
                    this.selectIds.push(value.id)
                    this.selectName.push(value.fullname)
                })
                this.priKey = this.selectName[0]
            },
            rowClass({row, rowIndex}){ // table选中后的样式
                if(this.selectRow.includes(rowIndex)){
                    return { "background-color": "#E9F3FD",
                        "color": "#409EFF" }
                }
            },
            handleSizeChange(size) { // 改变每页条数
                this.nowPage = 1
                this.nowSize = size
                this.init()
            },
            handleCurrentChange(page) {
                this.nowPage = page // 当前页设置
                this.init()
            },
            changeSelect(value) { // 更多的选项
                if(this.selectData.length === 0) {
                    let message
                    switch(value) {
                        case '1':
                            message = '发送邮件'
                            break
                        case '2':
                            message = '来往邮件'
                            break
                        case '3':
                            message = '合并'
                            break
                        case '4':
                            message = '共享'
                            break
                        case '5':
                            message = '转移'
                            break
                        case '6':
                            message = '取消跟进'
                            break
                        case '7':
                            message = '删除'
                            break
                    }
                    this.$message({
                        message: `请选择您要${message}的客户`,
                        type: "success"
                    })
                } else {
                    switch(value) {
                        case '1':
                            let str = '',arr=[];
                            if( this.selectData.length==1){
                                str=this.selectData[0].defaultEmail
                            }else{
                                this.selectData.forEach(item => {
                                    arr.push(item.defaultEmail)
                                });
                                str = arr.join(',')
                            }
                            this.$router.push({
                                path:'/mail/write/index',
                                query:{
                                    customer:str
                                }
                            })

                            break
                        case '2':
                            this.getCustomerInfo();
                            break
                        case '3':
                            this.signDialog = true
                            console.log('合并')
                            break
                        case '4':
                            this.shareDialog = true
                            this.selectTitle = "共享客户至以下用户"
                            break
                        case '5':
                            this.transferDialog = true
                            this.selectTitle = "转移客户至以下用户"
                            break
                        case '6':
                            this.cancel_show = true
                            console.log('取消跟进')
                            break
                        case '7':
                            this.delete_type = 'complex' // 多选删除
                            this.delete_show = true
                            break
                    }
                }
            },
            //获取客户信息
            getCustomerInfo() {
                queryCust(this.selectIds[0]).then(res => {
                    if (res.data.success) {
                        let link = res.data.data.custLinkDtos;
                        let result = []
                        if (link.length > 0) {
                            link.map(item => {
                                result.push(item.email)
                            })
                            getCustomerEmail(result,{userId:this.$route.params.userId},1);//获取往来邮件
                        } else {//没有邮箱 - 不需要跳转
                            this.$message({
                                message: '该用户未绑定邮箱，暂无往来邮件',
                                type: "success"
                            });
                        }
                    }
                })
            },
            preview(item, column, event) { // 右侧抽屉打开
                if(event.target.tagName !== 'I') {
                    this.nowId = item.id
                    this.visShow = true
                    this.drawerShow = true
                }
            },
            closeDrawer() {
                this.visShow = false
                this.drawerShow = false
            },
            floeUpChangePage(page) { // 跟进记录翻页
                this.nowPage = page
                getFlowUp(page,10, this.nowData.id, this.flowUpContent, this.timeSort,this.flowUpType).then(res => {
                    if (res.data.success) {
                        this.flowUpList = res.data.data.records
                        this.flowUpTotal = res.data.data.total
                    }
                })
            },
            searchFlowUp() {
                this.nowPage = 1
                getFlowUp(1,10, this.nowData.id, this.flowUpContent, this.timeSort,this.flowUpType).then(res => {
                    if (res.data.success) {
                        this.flowUpList = res.data.data.records
                        this.flowUpTotal = res.data.data.total
                    }
                })
            }
        },
    }
</script>

<style lang="scss">
  .custBox{
    .el-table__header-wrapper{
      background: rgb(234, 240, 246);
      height: 35px;
      line-height: 35px;
    }
  }

  .el-table__header{
    width: 100% !important;
  }
  .el-table__body{
    width:100% !important;
  }
  .cell{
    .el-rate__icon{
      font-size: 18px;
    }
  }
  .tag{
    .el-icon-close{
      color: white !important;
    }
  }
</style>

<style lang="scss" scoped>
  @import "../../styles/customer";
</style>



